package user.controllers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class LogoutServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {

		if (request.getUserPrincipal() != null) {
			UserService userService = UserServiceFactory.getUserService();
			
			String thisURL = request.getRequestURI();
			String url = userService.createLogoutURL(thisURL);
			response.sendRedirect(url);
			return;
		} else {
			response.sendRedirect("/");
			return;
		}
	}
}
